package vm;

import androidx.lifecycle.MutableLiveData;

import com.blankj.utilcode.util.ToastUtils;

import Entity.LoginStateMedel;

public class LoginModel extends BaseModel{



    //用户名
    private MutableLiveData<String> mNameEvent = new MutableLiveData<>();
    //密码
    private MutableLiveData<String> mPwEvent = new MutableLiveData<>();

    //登录状态
    private MutableLiveData<LoginStateMedel> LoginState = new MutableLiveData<>();

    //登录结果
    private LoginStateMedel loginResult=new LoginStateMedel();

    public MutableLiveData<String> getmPwEvent() {
        return mPwEvent;
    }

    public MutableLiveData<LoginStateMedel> getLoginState() {
        return LoginState;
    }



    public MutableLiveData<String> getNameEvent() {
        return mNameEvent;
    }

    public void login(String username,String pw,boolean isagreen){
        if(!isagreen){
            ToastUtils.showLong("请先同意隐私协议");
            return;
        }
        if(username==null||pw==null){
            ToastUtils.showLong("用户名或密码不能为空");
            return;
        }
        if(username.equals("xk1992")&&pw.equals("123456")){
            LoginState.postValue(loginResult.setLoginSuccess());
        }else {
            ToastUtils.showLong("登录失败");
        }
//        String MD5pw=EncryptUtils.encryptMD5ToString(pw).toUpperCase();
//        UtilX.LogX(MD5pw);
//        LoginState.postValue(loginResult.setLoginStart());
//        NetBase.getInstance().Login(username, MD5pw, new BaseObserver<ResponseBody>() {
//            @Override
//            public void onSuccess(ResponseBody stringResponse) {
//                LoginState.postValue(loginResult.setLoginSuccess());
//                String res= null;
//                try {
//                    res = stringResponse.string();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//                UtilX.LogX(res);
//                ErrorModel errorModel=new Gson().fromJson(res,ErrorModel.class);
//                ToastUtils.showLong(errorModel.getError().getMsg());
//            }
//
//            @Override
//            public void onFailure(Throwable e)
//            {
//                LoginState.postValue(loginResult.setLoginEnd(e.getMessage()));
//                UtilX.LogX(e.toString());
//            }
//        });
    }

}
